<?php 
/**
 * 默认访问控制器
 */
class IndexController extends CommonController{
	/*
	 *默认首页
	 */
	public function index(){
		
		//左侧分类数据*****************
		//获得所有的顶级分类数据
		$categoryData=M()->query("SELECT * FROM hd_category WHERE pid=0");
		//p($categoryData);exit;
		//循环顶级分类，重组数组，把子集压进去
		foreach ($categoryData as $k => $cate){
			$categoryData[$k]['son'] = M()->query("SELECT * FROM hd_category WHERE pid={$cate['cid']}");
		}
		//分配分类数据
		$this->assign('categoryData', $categoryData);
		//p($categoryData);die;
		
		//待解决问题******************
		$noSolve = M()->query("SELECT * FROM hd_ask WHERE solve=0 ORDER BY time DESC LIMIT 4");
		//分配出去
		$this->assign('noSolve',$noSolve);
		//高分悬赏问题*******************
		$maxReward =M()->query("SELECT * FROM hd_ask ORDER BY reward DESC LIMIT 4");
		$this->assign('maxReward',$maxReward);
		
		
		//右侧数据处理*********************
		//登陆以后用户的数据处理		
		if(isset($_SESSION['uid']) && isset($_SESSION['uname'])){
			$sql="SELECT * FROM hd_user WHERE uid='{$_SESSION['uid']}'";
			$userData=M()->query($sql);
//			p($userData);die;
			if($userData[0]['answer']!=0){
				$userData[0]['cnl']=$userData[0]['accept']/$userData[0]['answer'] *100 ;
				$userData[0]['cnl']=round($userData[0]['cnl'],2). "%";
			}else{
				$userData[0]['cnl']=0;
			}
			
			$userData[0]['lv']=$this->expToLv($userData[0]['exp']);
			//p($userData);
			$this->assign('userData',$userData[0]);
			
			
		}
		
		// 每日回答问题最多的人*********************
			$todayUid = $this->dayStar();
			//p($todayUid);die;
			if($todayUid){
			$uid = $todayUid[0]['uid'];
			$TodayAns = M()->query("SELECT * FROM hd_user WHERE uid={$uid}");
			//p($TodayAns);die
			$TodayAns[0]['lv']=$this->expTolv($TodayAns[0]['exp']);
			$this->assign('TodayAns',$TodayAns);
			//p($TodayAns);
		};
		
		
		
		//（历史记录）***********
		//接收这个值
		$historyArr=$this->historyStar();
		$historyArr = $historyArr[0];
		//它的经验对应的是经验值
		$historyArr['lv']=$this->expToLv($historyArr['exp']);
		
		$historyArr['accept_l']=$historyArr['accept']/$historyArr['answer']*100;
		$historyArr['accept_l']=round($historyArr['accept_l'],2) . '%';
//		p($historyArr);
		//分配出去
		$this->assign('historyArr',$historyArr);
		
			
		//(后盾问答助人光荣榜)*************
		$helpArr = $this->helpPeople();
		$this->assign('helpArr',$helpArr);
		
		//头部的问题库************************
		$this->topCate();

		
		$this->display();
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
}


 ?>